package com.leessy.r229.constants

import android.os.Environment
import com.leessy.r229.utils.MacAddressUtils
import java.io.File

/**
 *Global constant
 */
class Constants {
    companion object {
        val BaseURL = "http://120.78.145.155:8133"//equipment type
        val DEVICE_TYPE = "HPTC"//equipment type
        val SN: String

        var deviceLockAction = 0
        var deviceLockText:String?=""

        val rootPath: String
        val rootPath_Log: String//log文件类型存放
        val rootPath_Upgrade: String//log文件类型存放
        val otaFile: String//log文件类型存放

        val bucketName = "iot-szhpt"

        init {
            SN = snInit()
            rootPath = Environment.getExternalStorageDirectory().absolutePath + "/sysinfo"
            rootPath_Log = "$rootPath/Log".mkdirs()
            rootPath_Upgrade = "$rootPath/Upgrade".mkdirs()
            otaFile = "sdcard/update.zip"
        }

        //createFolder
        fun String.mkdirs(): String {
            File(this).mkdirs()
            return this
        }

        //sn generate etho mac -> wifi mac -> serial  ->Androidid (7ad84b8de17868e5)
        private fun snInit(): String {
            val m = MacAddressUtils.getEth0Mac()
            return if (m.isNullOrBlank()) {
                val seri = android.os.Build.SERIAL
                if (seri.isNullOrBlank()) {//substitute 1
                    return seri
                }
                ""
            } else {
                m.run {
                    replace(":", "").toUpperCase()
                }
            }
        }
    }

}